package org.hhchat.leetcode.string;

/**
 * Created this one by HMH on 2017/9/30.
 */
public class code345_easy {
    static class Solution {
        public String reverseVowels(String s) {
            int p = 0, q = s.length() - 1;
            StringBuilder stringBuilder = new StringBuilder(s);
            while (p < q) {
                while (p < q && !isVowels(s.charAt(p))) {
                    p++;
                }
                while (p < q && !isVowels(s.charAt(q))) {
                    q--;
                }
                char cp = s.charAt(p);
                char cq = s.charAt(q);
                stringBuilder.setCharAt(p++, cq);
                stringBuilder.setCharAt(q--, cp);
            }
            return stringBuilder.toString();
        }

        public boolean isVowels(char c) {
            switch (c) {
                case 'a':
                case 'A':
                case 'e':
                case 'E':
                case 'i':
                case 'I':
                case 'o':
                case 'O':
                case 'u':
                case 'U':
                    return true;
                default:
                    return false;
            }
        }
    }

    public static void main(String[] args){
        Solution solution = new Solution();
        System.out.println(solution.reverseVowels("hello"));
    }
}
